package kk.dao;

import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
import kk.domain.Permission;
import kk.domain.Role;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public interface RoleDao {

    /**
     * 根据用户的id查询出用户的角色
     * @param userId
     * @return
     */
    public List<Role> findRoleByUserId(Integer userId) throws Exception;

    /**
     * 查询所有角色
     * @return
     * @throws Exception
     */
    public List<Role> findAll() throws Exception;

    /**
     * 保存用户
     * @param role
     * @throws Exception
     */
    public void save(Role role) throws Exception;

    /**
     * 根据角色的id查询角色详细信息
     * @param id
     * @return
     * @throws Exception
     */
    public Role findById(Integer id) throws Exception;

    /**
     * 根据role的id删除users_role表中的数据
     * @param id
     * @throws Exception
     */
    public void deleteFromUsers_RoleByRoleId(Integer id) throws Exception;

    /**
     * 根据role的id删除role_permission表中的数据
     * @param id
     * @throws Exception
     */
    public void deleteFromRole_PermissionByRoleId(Integer id) throws Exception;

    /**
     * 根据role的id删除role表中的数据
     * @param id
     * @throws Exception
     */
    public void deleteFromRoleByRoleId(Integer id) throws Exception;

    /**
     * 查询出该角色没有的权限
     * @param roleId
     * @return
     * @throws Exception
     */
    public List<Permission> findOtherPermission(Integer roleId) throws Exception;

    /**
     * 给角色添加用户
     * @param roleId
     * @param permissionId
     */
    public void addPermissionToRole(@Param("roleId") Integer roleId , @Param("permissionId") Integer permissionId) throws Exception;


    /**
     * 查询该角色已经拥有的权限
     * @param roleId
     * @return
     */
    public List<Permission> findCanDeletePermission(Integer roleId);

    /**
     * 给角色删除权限
     * @param roleId
     * @param permissionId
     */
    public void deletePermissionFromRole(@Param("roleId") Integer roleId , @Param("permissionId") Integer permissionId);
}
